<template>
	<view>
		<image class="agent-img" src="../../static/temp/ad-splash.jpg" mode="widthFix"></image>
		<view class="agent-bottom">
			<view @tap="agentClick" class="agent-btn">支付{{price}}元成为代理</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				price: 0
			}
		},

		onLoad() {
			//获取成为代理参数
			this.getAgentParam();
		},

		methods: {
			//----------------------------点击---------------------------------------
			//支付成为代理
			agentClick: function() {
				if (uni.getStorageSync('userInfo')) {
					this.createOrderAgent();
				}
			},
			//创建升级代理订单
			createOrderAgent: function() {
				let than = this;
				than.$api.myPost({
					url: 'createOrderAgent',
					data: {
						userCode: uni.getStorageSync('userInfo').userCode
					},
					success(res) {
						if (res.status == 'success' && res.orderCode && res.price) {
							let data = {
								pageCode: 'agent',
								orderCode: res.orderCode,
								price: res.price
							}
							uni.navigateTo({
								url: '/pages/money/pay?data=' + encodeURIComponent(JSON.stringify(data))
							})
						} else {
							than.$api.msg(res.message)
						}
					}
				})
			},

			//获取成为代理参数
			getAgentParam: function() {
				let than = this;
				than.$api.myPost({
					url: 'getAgentParam',
					data: {},
					success(res) {
						if (res.status == 'success' && res.price) {
							than.price = res.price;
						}
					}
				})
			}
		}
	}
</script>

<style>
	.agent-img {
		width: calc(100% - 60rpx);
		margin: 40rpx 30rpx;
		float: left;
		margin-bottom: 180rpx;
	}

	.agent-bottom {
		width: 100%;
		position: fixed;
		bottom: 0;
		background-color: #fff;
	}

	.agent-btn {
		width: calc(100% - 60rpx);
		height: 100rpx;
		line-height: 100rpx;
		background-color: #FA436A;
		color: #fff;
		font-size: 30rpx;
		font-weight: bold;
		text-align: center;
		margin: 40rpx 30rpx;
		border-radius: 10rpx;
		float: left;
	}
</style>
